package cn.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

    @WebServlet("/login")
    public class login extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String name = request.getParameter("user");
            //判断用户名信息是否有效
            if (name==null||"".equals(name)) {
                //无效就重定向到登录界面
                response.sendRedirect("/stu/login.jsp");
                return;
            }
            /*获取会话域对象添加共享数据*/
            request.getSession().setAttribute("user",name);
            /*重定向到系统界面*/
            response.sendRedirect("/stu/index.jsp");
        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    }
